package com.lsp.microuser.user.controller;

import com.lsp.microcommon.common.CommonResult;
import com.lsp.microcommon.common.PageParam;
import com.lsp.microcommon.entity.User;
import com.lsp.microcommon.utils.UserUtils;
import com.lsp.microuser.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/app/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/upload/head")
    public CommonResult uploadHeadImg(MultipartFile file){

        return CommonResult.success(userService.uploadHeadImg(file));
    }
    @PostMapping("/upload/head2")
    public CommonResult uploadHeadImg2(MultipartFile file){
        return CommonResult.success(userService.uploadHeadImg2(file));
    }

    @GetMapping("/info")
    public CommonResult userInfo(){
        Integer uid = UserUtils.getUser();
        return CommonResult.success(userService.selectById(uid));
    }

    @PostMapping("/update")
    public CommonResult updateInfo(@RequestBody User user){
        Integer uid = UserUtils.getUser();
        user.setId(uid);
        userService.updateInfo(user);
        return CommonResult.success();
    }

    @GetMapping("/sign")
    public CommonResult sign(){
        userService.sign();
        return CommonResult.success();
    }


    @GetMapping("/my")
    public CommonResult myInfo(){

        return CommonResult.success(userService.myInfo());
    }

    @GetMapping("/score")
    public CommonResult pointInfo(PageParam param){
        return CommonResult.success(userService.selectPointList(param));
    }
}
